package com.jyh.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jyh.entity.User;
import com.jyh.service.UserService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author JYH
 * @version 1.0
 * @date 2022/11/17 16:41
 */
@RestController
@RequestMapping("/user")
@Api("增删改查")
public class UserController {
    @Autowired
    private UserService iUserService;

    @PostMapping("/insert")
    @ApiOperation("增")
    public int insert(@RequestBody User user){
        int insert = iUserService.insert(user);
        return insert;
    }

    @PostMapping("/delete")
    @ApiOperation("删")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "uid",value = "编号",required = true,dataType = "int")
    )
    public int delete(Integer uid){
        int i = iUserService.deleteById(uid);
        return i;
    }

    @PostMapping("/update")
    @ApiOperation("改")
    public int update(@RequestBody User user){
        int i = iUserService.updateById(user);
        return i;
    }

    @GetMapping("/find")
    @ApiOperation("查")
    @ApiImplicitParams(
            {@ApiImplicitParam(name = "currentPage",value = "页码",required = true,dataType = "int",defaultValue = "1")
            ,@ApiImplicitParam(name = "pageSize",value = "条数",required = true,dataType = "int",defaultValue = "5")
            }
    )
        public Page find(int currentPage, int pageSize){
        Page all = iUserService.findAll(currentPage, pageSize);
        return all;
    }

}
